package com.zero.guava.samples.ReentrantLock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SynDemo2 {

    public static void main(String[] args) {

        MyThread2 t2 = new MyThread2();
        new Thread(t2,"t1").start();
        new Thread(t2,"t2").start();
    }
}

class MyThread2 implements Runnable {

    private Lock lock = new ReentrantLock();

    @Override
    public void run() {
        lock.lock();
        try{
            for(int i=0;i<5;i++)
                System.out.println(Thread.currentThread().getName()+":"+i);
        }finally{
            lock.unlock();
        }

    }
}